#include <iostream>
#include <fstream>
#include <cstdlib>
#include "board.h"
#include "gameActions.h"

using namespace std;

struct point
{
        int x;
        int y;
};

int main()
{
        int row;
	int col;
        point lastMove;
	char response = 'Y';


	do 
	{
                system("CLS");
                
		int player = 1;
		int winner = 0;
		bool Tie = false;

		board Game;
		Game.printboard();
                col = Game.returnCols();
		row = Game.returnRows();

                gameActions Play( Game.returnArray(), col, row );

		while (winner == 0 && !Tie)
		{
			Tie = Play.checkTie();
			if (Tie)
			{
				cout<<"This Game ends in a TIE."<<endl;
					
			}

			/*int dropCol;
			dropCol = Play.getDropCol(row, col);
			Play.dropToken(dropCol, player);*/

                        Play.dropChecker(player, lastMove.x, lastMove.y);
                        system("CLS");
                        Game.printboard(Play.returnArray());

			winner = Play.checkWinnerRow(lastMove.y);
			if (winner != 0)
                        {
				break;
                        }

			winner = Play.checkWinnerCol(lastMove.x);
			if (winner != 0)
                        {
				break;
                        }

			winner = Play.checkWinnerDiag(lastMove.x, lastMove.y);
			if (winner != 0)
                        {
				break;
                        }
			
			Play.switchPlayer(player);

		}


		if (winner == 1)
			cout<<"Congradulations Player 1. You won this Game!"<<endl;
		if (winner == 2)
			cout<<"Congradulations Player 2. You won this Game!"<<endl;

	
		cout << "Would you like to play again. (y or n) -->";
		cin >> response;
		cout << endl;


	}while(toupper(response) == 'Y');

	return 0;
}
